# 2024/4/17 上午11:27 HFL
import json

import allure
import requests

from Utils.RequestUtils import Request
from Utils.utils import get_uuid, common_assert


# 登录接口

class TestLogin:

    # 生成验证码接口--正向：生成验证码成功
    @allure.title('生成验证码成功')
    @allure.severity(allure.severity_level.CRITICAL)
    def test01_get_verify_code(self):
        # 1.发送接口请求，获取响应数据
        url = 'http://kdtx-test.itheima.net' + '/api/captchaImage'
        resp = requests.get(url=url)
        common_assert(resp,200,200,'成功')

    # 登录接口--正向：登录成功（仅必填）
    @allure.title('登录成功（仅必填）')
    @allure.severity(allure.severity_level.CRITICAL)
    def test02_login_success(self):
        # 发送接口请求，获取响应数据
        uuid = get_uuid()
        url = 'http://kdtx-test.itheima.net' + '/api/login'
        login_json = {"username": "admin",
                      "password": "HM_2023_test",
                      "code": "2",
                      "uuid": uuid}
        request = Request()
        resp_login = request.post(url=url, json=login_json)
        common_assert(resp_login,200,200,'成功')


    # 登录接口--正向：登录失败（用户名为空）
    @allure.title('登录失败（用户名为空）')
    @allure.severity(allure.severity_level.NORMAL)
    def test03_login_user_none(self):
        # 发送接口请求，获取响应数据
        uuid = get_uuid()
        url = 'http://kdtx-test.itheima.net' + '/api/login'
        login_json = {"username": "",
                      "password": "HM_2023_test",
                      "code": "2",
                      "uuid": uuid}
        request = Request()
        resp_login = request.post(url=url, json=login_json)
        common_assert(resp_login,200,500,'错误')


    # 登录接口--正向：登录失败（密码为空）
    @allure.title('登录失败（密码为空）')
    @allure.severity(allure.severity_level.NORMAL)
    def test04_login_pwd_none(self):
        # 发送接口请求，获取响应数据
        uuid = get_uuid()
        url = 'http://kdtx-test.itheima.net' + '/api/login'
        login_json = {"username": "admin",
                      "password": "",
                      "code": "2",
                      "uuid": uuid}
        request = Request()
        resp_login = request.post(url=url, json=login_json)
        common_assert(resp_login,200,500,'错误')


    # 登录接口--正向：登录失败（验证码为空）
    @allure.title('登录失败（验证码为空）')
    @allure.severity(allure.severity_level.NORMAL)
    def test05_login_verify_none(self):
        # 发送接口请求，获取响应数据
        uuid = get_uuid()
        url = 'http://kdtx-test.itheima.net' + '/api/login'
        login_json = {"username": "admin",
                      "password": "HM_2023_test",
                      "code": "",
                      "uuid": uuid}
        request = Request()
        resp_login = request.post(url=url, json=login_json)
        common_assert(resp_login,200,500,'错误')
